package com.spring.appservice.web.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.google.common.collect.Maps;
import com.spring.appservice.web.service.MainShowService;
import com.spring.security.core.annotation.Log;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.model.BaseResult;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Controller
@RequestMapping(value = "/mainShow")
public class MainShowController {
	
	@Resource private MainShowService mainShowService;
	
	@RequestMapping(value = "/getLastAppVersion", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "app首页接口", httpMethod = "GET", response = Object.class, notes = "app首页接口",produces = "application/json; charset=utf-8")    
    @Log(value="app首页调用")
    public Object getLastAppVersion(@ApiParam(required = false, name = "packageName", value = "包名")@RequestParam(value="packageName",required = false)String packageName,
    		@ApiParam(required = false, name = "appID", value = "appID")@RequestParam(value="appID",required = false)String appID,
    		@ApiParam(required = true, name = "appType", value = "app类型 iso 2 安卓 1")@RequestParam String appType
    		) throws Exception{
		BaseResult rt = null;
    	try{
    		rt = mainShowService.getLastAppVersion(packageName,appID,appType);
    	}catch(Exception e){
    		rt=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        return rt;
    }
	
    @RequestMapping(value = "/banner", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "banner查询", httpMethod = "GET", response = Object.class, notes = "app首页接口",produces = "application/json; charset=utf-8")    
    public Object banner(
    		@ApiParam(required = true, name = "bannerType", value = "banner类型")@RequestParam String bannerType,
    		@ApiParam(required = true, name = "skip", value = "分页")@RequestParam(value="skip",required = false) String skip,
    		@ApiParam(required = true, name = "rows", value = "分页")@RequestParam(value="rows",required = false) String rows,    		
    		String callback) throws Exception{
		BaseResult br=null;
    	try{
    		br = mainShowService.banner(bannerType, skip, rows);
    	}catch(Exception e){
    		br=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, br);
        }else{
        	return br;
        }
    }
    
	
	
	
	
	
    @RequestMapping(value = "/homeShow", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "app首页接口", httpMethod = "GET", response = Object.class, notes = "app首页接口",produces = "application/json; charset=utf-8")    
    @Log(value="app首页调用")  
    public Object homeShow(@ApiParam(required = true, name = "kids_parkID", value = "乐园编号")@RequestParam String kids_parkID,
    		@ApiParam(required = true, name = "token", value = "token") String token,
    		String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.homeShow(kids_parkID,token);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }
    
    @RequestMapping(value = "/homeMemberShow", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "app首页会员接口", httpMethod = "GET", response = Object.class, notes = "app首页会员接口",produces = "application/json; charset=utf-8")    
    @Log(value="app首页会员接口")  
    public Object homeMemberShow(@ApiParam(required = true, name = "kids_parkID", value = "乐园编号")@RequestParam String kids_parkID,
    		@ApiParam(required = true, name = "token", value = "token")@RequestParam String token,
    		String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.homeMemberShow(kids_parkID,token);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }
    
    @RequestMapping(value = "/getActivitiesList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取活动列表", httpMethod = "GET", response = Object.class, notes = "获取活动列表",produces = "application/json; charset=utf-8")    
    @Log(value="获取活动列表")  
    public Object getActivitiesList(String kidsParkID,String skip,String rows) throws Exception{
    	BaseResult br = null;
    	try{
    		br = mainShowService.getActivitiesList(kidsParkID,skip,rows);
	
    	}catch(Exception e){
    		br=new BaseResult("0","系统异常");
    		e.printStackTrace();
    	}
        	return br;

    } 

		
	@RequestMapping(value = "/getNewsList", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "获取新闻列表", httpMethod = "GET", response = Object.class, notes = "获取新闻列表",produces = "application/json; charset=utf-8")    
	@Log(value="获取新闻列表")  
	public Object getNewsList(HttpServletRequest request,String newsID,
			/*@ApiParam(required = true, name = "newsType", value = "新闻类型 1: 亲子育儿 ")*/String newsType,
			String skip,String rows,String callback) throws Exception{
		BaseResult br = null;
		try {
			br = mainShowService.getNewsList(newsID, newsType, skip, rows,request);
		} catch (Exception e) {
			br = new BaseResult("0", "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, br);
		} else {
			return br;
		}
	}
	
	
/*	@RequestMapping(value = "/updateReadCount", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "修改阅读数量", httpMethod = "POST", response = Object.class, notes = "修改阅读数量",produces = "application/json; charset=utf-8")    
	@Log(value="修改阅读数量")  
	public Object updateReadCount(String id,@ApiParam(required = true, name = "kids_parkID", value = "类型 1 news 2 activity 3 日志 ")String type) throws Exception{
		BaseResult br = null;
		try{
			br = mainShowService.updateReadCount(id, type);
		}catch(Exception e){
			br=new BaseResult("0","系统异常");
			e.printStackTrace();
		}
	    	return br;
	}*/	

    @RequestMapping(value = "/productShow")
    @ResponseBody
    public Object productShow(String kids_parkID,String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.productShow(kids_parkID);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }
    
    
    
    @RequestMapping(value = "/getProductShowDetail")
    @ResponseBody
    public Object getProductShowDetail(String productShowID,String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.getProductShowDetail(productShowID);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }
    
    
    @RequestMapping(value = "/meShow")
    @ResponseBody
    public Object meShow(String token,String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.meShow(token);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }
      
	@RequestMapping(value = "/getMyBabyList")
	@ResponseBody
	@ApiOperation(value = "获取宝宝列表", httpMethod = "GET", response = Object.class, notes = "获取宝宝列表", produces = "application/json; charset=utf-8")
	@Log(value = "获取宝宝列表")
	public Object getMyBabyList(
			@RequestParam(value="token",required = false)String token,
			@ApiParam(required = false, name = "babyID", value = "宝宝id可选 ")@RequestParam(value="babyID",required = false) String babyID,
			@RequestParam(value="callback",required = false)String callback) throws Exception {
		BaseResult br = null;
		try {
			br = mainShowService.getMyBabyList(token, babyID);
		} catch (Exception e) {
			br = new BaseResult("0", "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, br);
		} else {
			return br;
		}

	}
	
	@RequestMapping(value = "/kidsPark")
	@ResponseBody
	@ApiOperation(value = "获取乐园列表", httpMethod = "GET", response = Object.class, notes = "获取乐园列表", produces = "application/json; charset=utf-8")
	@Log(value = "获取乐园列表")
	public Object kidsPark(@RequestParam(value="callback",required = false)String callback) throws Exception {
		BaseResult br = null;
		try {
			br = mainShowService.kidsPark();
		} catch (Exception e) {
			br = new BaseResult("0", "系统异常");
			e.printStackTrace();
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, br);
		} else {
			return br;
		}

	}
}
